<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	template="/WEB-INF/templates/template.xhtml">
	
	<ui:define name="headIncludes">
		<f:event listener="#{usuarioBean.initializeForm(param.usuarioId)}" type="preRenderView"/>
	</ui:define>
	
	<ui:define name="pageName">#{usuarioBean.acao}</ui:define>
	<ui:define name="buttons">
		<p:commandButton value="Salvar" style="height:28px;" action="#{usuarioBean.save}" update="@this, messageFormUsuario" icon="ui-icon-disk"/>
		<p:commandButton value="Voltar" style="height:28px;" action="#{usuarioBean.changeToList}" process="@this" icon="ui-icon-arrowreturnthick-1-w"/>			
	</ui:define>
	
	<ui:define name="content">	
		<p:panel>
			<div>
				<p:messages id="messageFormUsuario"/>
				<h:panelGrid columns="2" style="padding:5px;">
					<h:outputText value="Código" />
					<h:outputText value="Nome *" />
					<p:inputText style="width:100px;" disabled="true" value="#{usuarioBean.currentUsuario.id}"/>
					<p:inputText style="width:300px;" value="#{usuarioBean.currentUsuario.nome}" required="true" requiredMessage="Informe o nome." maxlength="50"/>
				</h:panelGrid>
					
				<h:panelGrid columns="2" style="padding:5px;">
					<h:outputText value="Login *" />
					<h:outputText value="E-mail *" />
					
					<p:inputText style="width:150px;" value="#{usuarioBean.currentUsuario.login}" required="true" requiredMessage="Informe o login." maxlength="20"/>
					<p:inputText style="width:250px;" value="#{usuarioBean.currentUsuario.email}" maxlength="100"/>
				</h:panelGrid>
					
				<h:panelGrid columns="4" style="padding:5px;">			
					<h:outputText value="Senha *" />		
					<h:outputText value="Confirmar senha *" />	
					<h:outputText value="Perfil *" />		
					<h:outputText value="" />	
						
					<p:password style="width:150px;"
						match="inputConfPassword" maxlength="20"
						required="#{usuarioBean.currentUsuario.id == null}"
						requiredMessage="Senha é obrigatória."
						validatorMessage="Senha e confirmação de senha devem ser iguais."/>
						
					<p:password style="width:150px;" id="inputConfPassword" maxlength="20"/>					
					
					<p:autoComplete id="inputPerfil" var="perfil" value="#{usuarioBean.currentUsuario.perfil}" maxlength="30"
						itemLabel="#{perfil.perfil}" itemValue="#{perfil}" size="50" required="true" requiredMessage="Selecione o perfil."
						converter="perfilConverter" completeMethod="#{usuarioBean.getPerfilByQuery}">
						<p:ajax event="itemSelect" process="@this inputPerfil"/>
					</p:autoComplete>
					
					<p:commandButton icon="ui-icon-search" style="height:24px;" actionListener="#{usuarioBean.openDialogListPerfil}" process="@this" title="Selecionar perfil"/>					
				</h:panelGrid>
				
				<h:panelGrid columns="1" style="padding:5px;">
					<h:outputText value="* Campos obrigatórios" />
				</h:panelGrid>
			</div>
		</p:panel>
	</ui:define>	
	<ui:define name="popups">
		<ui:include src="listPerfil.xhtml"/>
		<ui:include src="formPerfil.xhtml"/>
	</ui:define>
</ui:composition>